사이트 내 전체검색
PHP
[php] 엑셀파일(xls, cvs)로 불러오기 내보내기
로빈아빠
https://cmd.kr/php/520 URL이 복사되었습니다.

본문

엑셀파일(xls, cvs)로 불러오기 내보내기

우선 불러오는 방법
http://sourceforge.net/projects/phpexcelreader/
에서 소스를 다운받은후 사용하시면 됩니다.
한글 지원은..
$data->setOutputEncoding('CP949'); 
이렇게 고치면 됩니다.

문론 cvs로 고쳐서 불러 들여되 됩니다.

내보는 방법은 cvs를 이용하여 '탭'이나 ',' 로 분리자를 줘서 출력하면 됩니다.
ex 1)
<? 
	Header("Content-type: application/octet-stream");
	Header("Content-Transfer-Encoding: binary");
	Header("Content-Disposition: attachment; filename=member_".$today.".csv");
	Header("Pragma: no-cache");
	Header("Expires: 0");
	$query = "select * from arbeit_companymember order by no desc  ";
	$result = mysql_query($query);
	
	echo <<< TEXT
"가입경로","아이디","회사명","사업번호","대표자","회사번호","팩스번호","회사홈페이지","회사이메일","이름","이메일","전화번호","핸드폰번호","우편번호","주소","소재지","가입일"

TEXT;
	
	while($row = mysql_fetch_array($result))
	{
	if($row[phone]=='--') $row[phone] = '';
	if($row[hphone]=='--') $row[hphone] = '';
	if($row[fax]=='--') $row[fax] = '';
	if($row[companynum]=='--') $row[companynum] = '';
	if($row[homepage]=='http://') $row[homepage] = '';
	
		echo <<<QWER
"$addlink","$row[uid]","$row[companyname]","$row[companynum]","$row[ownername]","$row[company_phone]","$row[fax]","$row[homepage]","$row[company_email]","$row[name]","$row[email]","$row[phone]","$row[hphone]","$row[post]","$row[addr1]","$row[addr2]","$row[wdate]"

QWER;
	}
?> 


ex 2) mysql테이블에서 내용 불러오기
<? 
$xls_filename        = "filename.xls"; 

$connect=@mysql_connect($connect_host,$connect_id,$connect_pass); 
$mysql=@mysql_select_db($connect_db,$connect); 

header("Content-Type: application/vnd.ms-excel");  
header("Content-Disposition: attachment; filename=$xls_filename");  
?>  

<html>  
<head>  
<meta http-equiv=Content-Type content=text/html; charset=EUC-KR> 
</head>  
<body>  
<table border=1> 
<tr align=center> 
<? 
$fields = mysql_list_fields("$connect_db", "$connect_table"); 
$columns = mysql_num_fields($fields); 

for ($i = 0; $i < $columns; $i++) { 
$field[$i]=mysql_field_name($fields, $i); 
  echo "<th>".$field[$i]. "</th>"; 
} 
?> 
</tr> 

<? 
$result=mysql_query("select * from $connect_table"); 
while($data=mysql_fetch_assoc($result)){ 
echo"<tr>"; 

for ($i = 0; $i < sizeof($field); $i++) { 
echo "<td>".$data["$field[$i]"]."</td>"; 
} 

echo"</tr>"; 
} 
?> 
</table> 
</body>  
</html>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (9/18P)

Search

Copyright © Cmd 명령어 3.14.80.22